package zut.edu.cn.concertticketmanagementsystem.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zut.edu.cn.concertticketmanagementsystem.Dao.CollectDao;
import zut.edu.cn.concertticketmanagementsystem.entity.Collect;
import zut.edu.cn.concertticketmanagementsystem.service.Collectservice;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class CollectserviceImpl implements Collectservice {
    @Autowired
    private CollectDao collectDao;
    @Override
    public boolean create(Collect collect) {
        boolean flag=false;
        Collect collect1=new Collect();
        List<Collect>list=new ArrayList<Collect>();
        list=collectDao.findByUseridAndPid(collect.getUserid(),collect.getPid());
        if(list.size()==0)
        {
            collect1=collectDao.save(collect);
            if(collect1!=null)
                flag=true;
            else flag=false;
        }
        else
            flag=false;
        return flag;
    }

    @Override
    public boolean delete(Collect collect) {
        boolean flag=true;
        List<Collect>list=collectDao.findByUseridAndPid(collect.getUserid(),collect.getPid());
        for(int i=0;i<list.size();++i)
        collectDao.deleteById(list.get(i).getCid());
        return flag;
    }

    @Override
    public List<Collect> findbyUserid(int id) {

        return collectDao.findByUserid(id);
    }
}
